var express = require('express');
const multer = require('multer')
const path = require("path");
var router = express.Router();
// const upload = multer({dest: 'upload/'}) // 1.定义文件的存放位置，不带 / 的是相对位置
//获取绝对路径
// let fullPath=path.resolve(__dirname+"/attachment");
//设置文件的名称
let filename="";
let storage=multer.diskStorage({
    //设置存储路径
    destination:(req,file,cb)=>{
        cb(null,'E:\\test/');
    },
    //设置存储的文件名
    filename:(req,file,cb)=>{
        // 解决中文名乱码的问题
        file.originalname = Buffer.from(file.originalname, "latin1").toString(
            "utf8"
        );
        //获取文件的扩展名
        let extname=path.extname(file.originalname);
        filename=file.originalname;
        cb(null,filename);
    }
})
let upload=multer({storage});

//文件上传
router.post("/upload_file", upload.any(), require("../controllers/upload/upload_file"));


module.exports = router;